import os

f = open("test.txt", mode="a+", encoding="utf-8", buffering=8192)
f.write("test")
f.flush()
f.seek(0)
print(f.readline())
print(f.tell())
f.seek(0)
print(f.readlines())
f.close()

with open("test.txt", "rb+") as g:
    print(g.read().decode("utf-8"))
    g.truncate(2)
    g.seek(0)
    print(g.read())

os.remove("test.txt")
